package com.lijie.ljblog.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.lijie.ljblog.model.Diary;
import com.lijie.ljblog.service.DiaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Title: ljblog_springboot
 * @Description: (更新记录 控制层)
 * @Author:lijie
 * @Version:1.1.0
 * @since 2021/11/10
 */
@RestController
@RequestMapping("/ljblog/Diary")
public class DiaryController {
    @Autowired
    DiaryService diaryService;

    @RequestMapping("saveOrUpdate")
    public boolean  addDiary(@RequestBody Diary diary){
        return diaryService.saveOrUpdate(diary);
    }
    @RequestMapping("deleteDiary")
    public boolean  deleteDiary(@RequestBody Diary diary){
        boolean res=false   ;
        if(diary.getId()!=null){
            res= diaryService.removeById(diary.getId());
        }
        return res;
    }
    @RequestMapping("getDiaryList/{page}")
    public PageInfo<Diary> getDiaryList(@PathVariable Integer page){
        return diaryService.listDiary(page);
    }

    @RequestMapping("getAllDiary")
    public List<Diary> getAllDiary(){
        QueryWrapper<Diary>queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("Time");
        return diaryService.list(queryWrapper);
    }
}
